//
//  LGTeamApproveCell.m
//  BreathTrainingTool
//
//  Created by 1234 on 2024/7/15.
//

#import "LGTeamApproveCell.h"

@interface LGTeamApproveCell()
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UILabel *tipLabel;
/**   */
@property (nonatomic , strong)UIButton *refuseBtn;
/**   */
@property (nonatomic , strong)UIButton *agreeBtn;

@end

@implementation LGTeamApproveCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"avatar"])] placeholderImage:defaultDoctor];
    self.nameLabel.text = LGNSString(dataDic[@"userName"]);
    self.timeLabel.text = LGNSString(dataDic[@"createTime"]);
    //status:0-待审批 、 1-已同意 、 2-已拒绝
    NSDictionary *titleDic = @{@"0":@"同意",@"1":@"已同意",@"2":@"已拒绝"};
    self.refuseBtn.hidden = [dataDic[@"status"] integerValue]==0?NO:YES;
    self.agreeBtn.selected = [dataDic[@"status"] integerValue]>0?YES:NO;
    [self.agreeBtn setTitle:titleDic[LGNSString(dataDic[@"status"])] forState:UIControlStateNormal];
    self.agreeBtn.userInteractionEnabled = [dataDic[@"status"] integerValue]>0?NO:YES;
}

//拒绝
-(void)refuseBtnAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(refuseTeamApprove:)]) {
        [self.delegate refuseTeamApprove:LGNSString(self.dataDic[@"id"])];
    }
}

//同意
-(void)agreeBtnAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(agreeTeamApprove:)]) {
        [self.delegate agreeTeamApprove:LGNSString(self.dataDic[@"id"])];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.type = LGPositionTypeSingle;
    [self.baseView addSubview:self.headPic];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.tipLabel];
    [self.baseView addSubview:self.refuseBtn];
    [self.baseView addSubview:self.agreeBtn];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(14));
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(12));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel);
        make.right.equalTo(self.baseView).offset(-viewPix(16));
    }];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.nameLabel);
    }];
    
    [self.refuseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.agreeBtn.mas_left).offset(-viewPix(10));
        make.centerY.equalTo(self.agreeBtn);
        make.width.equalTo(@(viewPix(65)));
        make.height.equalTo(@(viewPix(28)));
    }];
    
    [self.agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tipLabel.mas_bottom).offset(viewPix(10));
        make.right.equalTo(self.baseView).offset(-viewPix(16));
        make.width.equalTo(@(viewPix(75)));
        make.height.equalTo(@(viewPix(28)));
        make.bottom.equalTo(self.baseView).offset(-viewPix(16));
    }];
}
-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(16), viewPix(42), viewPix(42))];
        _headPic.image = [UIImage imageNamed:@""];
        _headPic.cornerRidus = viewPix(21);
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#2B2A37" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UILabel *)tipLabel{
    if(!_tipLabel){
        _tipLabel = [UILabel lableWithText:@"申请加入您的咨询团队" colorString:@"#606266" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _tipLabel;
}

-(UIButton *)refuseBtn{
    if(!_refuseBtn){
        _refuseBtn = [UIButton buttonWithTitle:@"拒绝" titleFont:LGFont(14) normalColor:@"#796DF5" selectColor:@"#796DF5"];
        [_refuseBtn addBorder:@"#796DF5" lineWidth:1 cornerRidus:viewPix(14)];
        [_refuseBtn addTarget:self action:@selector(refuseBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _refuseBtn;
}

-(UIButton *)agreeBtn{
    if(!_agreeBtn){
        _agreeBtn = [UIButton buttonWithTitle:@"同意" titleFont:LGFont(14) normalColor:@"#FFFFFF" selectColor:@"#606266"];
        [_agreeBtn setBackgroundColor:kThemeColor selectColor:@"#E9E9EB"];
        _agreeBtn.cornerRidus = viewPix(14);
        [_agreeBtn addTarget:self action:@selector(agreeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _agreeBtn;
}

@end
